package com.dh.teacher;

import org.aspectj.lang.ProceedingJoinPoint;

/*@Aspect
@Component*/
public class TeacherAspectJ {

    /*@Pointcut("execution(* com.dh.teacher.Teacher.teach(..)) && within(com.dh..teacher.*) && bean(mathTeacher)")
    public void point() {
    }

    @Before("point()")
    public void beforeTeach() {
        System.out.println("老师开始上课...(Before)");
    }

    @After("point()")
    public void afterTeach() {
        System.out.println("下课了...（After）");
    }

    @AfterReturning("point()")
    public void afterReturningTeach() {
        System.out.println("AfterReturning...");
    }

    @Around("point()")
    public void aroundTeach(ProceedingJoinPoint joinPoint) {
        try {
            System.out.println("Around before...");
            joinPoint.proceed();
            System.out.println("Around after...");
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
    }*/

    /*@Pointcut("execution(String com.dh.teacher.Teacher.teach(int)) && args(floor)")
    public void point(int floor) {
    }

    @Around("point(floor)")
    public String aroundTeach(ProceedingJoinPoint joinPoint, int floor) {
        Object res = "";
        try {
            res = joinPoint.proceed();
            if (floor == 1) {
                res = res + "拖堂了";
            } else {
                res = res + "正常下课";
            }
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        return (String) res;
    }*/

    /*public void beforeTeach() {
        System.out.println("老师开始上课...(Before)");
    }

    public void afterTeach() {
        System.out.println("下课了...（After）");
    }

    public void afterReturningTeach() {
        System.out.println("AfterReturning...");
    }*/

    public String aroundTeach(ProceedingJoinPoint joinPoint, int floor) {
        Object res = "";
        try {
            res = joinPoint.proceed();
            if (floor == 1) {
                res = res + "拖堂了";
            } else {
                res = res + "正常下课";
            }
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        return (String) res;
    }
}
